import { defineConfig } from 'vite'
import { resolve } from 'path'
import react from '@vitejs/plugin-react'
import svgr from 'vite-plugin-svgr'
import { viteMockServe } from 'vite-plugin-mock'

function loadVitePlugins() {
  return [
    react(),
    svgr(),
    viteMockServe({
      mockPath: 'mock',
      watchFiles: true
    }),
  ]
}

// https://vitejs.dev/config/
export default defineConfig({
  plugins: loadVitePlugins(),
  resolve: {
    alias: {
      "@": resolve(__dirname, 'src')
    }
  },
  server: {
    port: 5188,
    proxy: {
      '/dev': {
        target: 'http://localhost:3000',
        changeOrigin: true,
        rewrite: path => path.replace(/^\/dev/, '')
      }
    }
  }
})
